[#--

This is a basic default form macro library that let page author to quickly create form that 
utilizing formData object that auto expose by the Sweet Framework.

--]

[#macro form action="${reqRoute.handlerPath}" method="post"]
<link rel="stylesheet" href="${reqRoute.contextPath}/view/layout/tableform.css" type="text/css" />
<form class="tableform" id="${formData.formName}" name="${formData.formName}" 
  action="${action}" method="${method}">
<table class="tableform">
	[#nested]
</table>
</form>	
[/#macro]

[#macro singleRowInput name="field"]
	[#assign field = formData.fields[name]]
	<tr class="tableformTRRow">
		<td class="tableformTDLabel">
			[#if field.isRequired]<span class="tableformTDLabelRequired"> *</span>[/#if]
			${field.label}
		</td>
		<td class="tableformTDInput">
			[#nested]
		</td>
		<td class="tableformTDError">
			[#if formData.errors[name]??]
			<ul class="tableformTDErrorUL">[#list formData.errors[field.name] as err]<li>${err}</li>[/#list]</ul>
			[/#if]
		</td>
	</tr>
[/#macro]


[#macro submit name="submit" value="Submit"]	
	<tr class="tableformTRControls">
		<td class="tableformTDControlsLeft"></td>
		<td class="tableformTDControls">
			<input class="tableformSubmit" type="submit" name="${name}" value="${value}"/>
		</td>
		<td class="tableformTDControlsRight"></td>
	</tr>
[/#macro]


[#macro input type="text" name="${type}" size="35" maxlength=""]
	[@singleRowInput name="${name}"]
		<input class="tableform" type="${type}" name="${formData.formName}.${name}" 
			value="${formData.singleValues[name]}" size="${size}" maxlength="${maxlength}"/>	
	[/@singleRowInput]
[/#macro]

[#macro textarea name="textarea" rows="5", cols="25"]	
	[@singleRowInput name="${name}"]
		<textarea class="tableform" name="${formData.formName}.${name}" 
			rows="${rows}" cols="${cols}">${formData.singleValues[name]}</textarea>
	[/@singleRowInput]
[/#macro]

[#macro checkbox name="checkbox"]
	[@singleRowInput name="${name}"]
		[#list field.multiValuesKeys as mutlValKey]
		[#assign value = field.multiValues[mutlValKey]]
		<input class="tableformInputCheckbox" type="checkbox" name="${formData.formName}.${name}" value="${value}"
			[#if formData.multiValues[field.name]?size > 0 && formData.multiValues[field.name]?seq_contains(value)]
				checked="true"
			[/#if]
			/> ${mutlValKey}
		[/#list]
	[/@singleRowInput]
[/#macro]

[#macro radio name="radio"]	
	[@singleRowInput name="${name}"]
		[#list field.multiValuesKeys as mutlValKey]
		[#assign value = field.multiValues[mutlValKey]]
		<input class="tableformInputRadio" type="radio" name="${formData.formName}.${name}" value="${value}"
			[#if formData.multiValues[field.name]?size > 0 && formData.multiValues[field.name]?seq_contains(value)]
				checked="true"
			[/#if]
			/> ${mutlValKey}
		[/#list]
	[/@singleRowInput]
[/#macro]

[#macro select multiple="false" name="multi-select"]	
	[@singleRowInput name="${name}"]
		<select class="tableform"  name="${formData.formName}.${name}"
			[#if multiple=="true"]multiple="true" size="${field.multiValuesKeys?size}"[/#if]>
		[#list field.multiValuesKeys as mutlValKey]
			[#assign value = field.multiValues[mutlValKey]]
			<option class="tableform" value="${value}"
				[#if formData.multiValues[field.name]?size > 0 && formData.multiValues[field.name]?seq_contains(value)]
					selected="true"
				[/#if]
				/> ${mutlValKey} </option>
		[/#list]
		</select>
	[/@singleRowInput]
[/#macro]

